﻿using System;
using WorkOrder.Business;
using System.Data;

namespace WorkOrder
{
    public partial class monthReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["UserID"] == null || Session["UserID"].ToString() == "")
            {
                Session.Clear();
                ClientScript.RegisterClientScriptBlock(this.GetType(), "windowhref", "<script type='text/javascript'>alert('对不起，您还没有登录系统！');window.parent.location.href='../login.aspx';</script>");
            }
            if (!Page.IsPostBack)
            {
                txtYear.Value = DateTime.Now.Year.ToString();
                seleMonth.Value = DateTime.Now.Month.ToString();

                FillData();
            }
        }

        protected void btnSearch_ServerClick(object sender, EventArgs e)
        {
            FillData();
        }

        private void FillData()
        {
            MonthReport mr = new MonthReport();
            string str="";
            string str3= "'" + DateTime.Now.Year.ToString() + "-" + (DateTime.Now.Month).ToString() + "-1 0:0:0' and '" + DateTime.Now.ToString() + "'";
            string str2 = "'" + DateTime.Now.Year.ToString() + "-" + (DateTime.Now.Month - 1).ToString() + "-1 0:0:0' and '" + 
                DateTime.Now.Year.ToString() + "-" + (DateTime.Now.Month).ToString() + "-1 0:0:0'";
            #region 查询条件
            if (txtYear.Value.Trim() != "")
            {
                switch (seleMonth.Value)
                {
                    case "1":
                        str = txtYear.Value + "-1-1 0:0:0' and '" + txtYear.Value + "-1-31 23:59:59'";
                        str2 = (Convert.ToInt32(txtYear.Value) - 1).ToString() + "-12-1 0:0:0' and '" + (Convert.ToInt32(txtYear.Value) - 1).ToString() + "-12-31 23:59:59'";
                        str3 = "'" + txtYear.Value + "-1-1 0:0:0' and '" + txtYear.Value + "-1-31 23:59:59'";
                        break;
                    case "2":
                        if (Convert.ToInt32(txtYear.Value) % 4 == 0)
                        {
                            str = txtYear.Value + "-2-1 0:0:0' and '" + txtYear.Value + "-2-29 23:59:59'";
                            str3 = "'" + txtYear.Value + "-2-1 0:0:0' and '" + txtYear.Value + "-2-29 23:59:59'";
                        }
                        else
                        {
                            str = txtYear.Value + "-2-1 0:0:0' and '" + txtYear.Value + "-2-28 23:59:59'";
                            str3 = "'" + txtYear.Value + "-2-1 0:0:0' and '" + txtYear.Value + "-2-28 23:59:59'";
                        }
                        str2 = txtYear.Value + "-1-1 0:0:0' and '" + txtYear.Value + "-1-31 23:59:59'";
                        break;
                    case "3":
                        str = txtYear.Value + "-3-1 0:0:0' and '" + txtYear.Value + "-3-31 23:59:59'";
                        str3 = "'" + txtYear.Value + "-3-1 0:0:0' and '" + txtYear.Value + "-3-31 23:59:59'";
                        if (Convert.ToInt32(txtYear.Value) % 4 == 0)
                            str2 = txtYear.Value + "-2-1 0:0:0' and '" + txtYear.Value + "-2-29 23:59:59'";
                        else
                            str2 = txtYear.Value + "-2-1 0:0:0' and '" + txtYear.Value + "-2-28 23:59:59'"; 
                        break;
                    case "4":
                        str = txtYear.Value + "-4-1 0:0:0' and '" + txtYear.Value + "-4-30 23:59:59'";
                        str2 = txtYear.Value + "-3-1 0:0:0' and '" + txtYear.Value + "-3-31 23:59:59'";
                        str3 = "'" + txtYear.Value + "-4-1 0:0:0' and '" + txtYear.Value + "-4-30 23:59:59'";
                        break;
                    case "5":
                        str = txtYear.Value + "-5-1 0:0:0' and '" + txtYear.Value + "-5-31 23:59:59'";
                        str2 = txtYear.Value + "-4-1 0:0:0' and '" + txtYear.Value + "-4-30 23:59:59'";
                        str3 = "'" + txtYear.Value + "-5-1 0:0:0' and '" + txtYear.Value + "-5-31 23:59:59'";
                        break;
                    case "6":
                        str = txtYear.Value + "-6-1 0:0:0' and '" + txtYear.Value + "-6-30 23:59:59'";
                        str2 = txtYear.Value + "-5-1 0:0:0' and '" + txtYear.Value + "-5-31 23:59:59'";
                        str3 = "'" + txtYear.Value + "-6-1 0:0:0' and '" + txtYear.Value + "-6-30 23:59:59'";
                        break;
                    case "7":
                        str = txtYear.Value + "-7-1 0:0:0' and '" + txtYear.Value + "-7-31 23:59:59'";
                        str2 = txtYear.Value + "-6-1 0:0:0' and '" + txtYear.Value + "-6-30 23:59:59'";
                        str3 = "'" + txtYear.Value + "-7-1 0:0:0' and '" + txtYear.Value + "-7-31 23:59:59'";
                        break;
                    case "8":
                        str = txtYear.Value + "-8-1 0:0:0' and '" + txtYear.Value + "-8-31 23:59:59'";
                        str3 = "'" + txtYear.Value + "-8-1 0:0:0' and '" + txtYear.Value + "-8-31 23:59:59'";
                        str2 = txtYear.Value + "-7-1 0:0:0' and '" + txtYear.Value + "-7-31 23:59:59'";
                        break;
                    case "9":
                        str = txtYear.Value + "-9-1 0:0:0' and '" + txtYear.Value + "-9-30 23:59:59'";
                        str3 = "'" + txtYear.Value + "-9-1 0:0:0' and '" + txtYear.Value + "-9-30 23:59:59'";
                        str2 = txtYear.Value + "-8-1 0:0:0' and '" + txtYear.Value + "-8-31 23:59:59'"; 
                        break;
                    case "10":
                        str = txtYear.Value + "-10-1 0:0:0' and '" + txtYear.Value + "-10-31 23:59:59'";
                        str2 = txtYear.Value + "-9-1 0:0:0' and '" + txtYear.Value + "-9-30 23:59:59'";
                        str3 = "'" + txtYear.Value + "-10-1 0:0:0' and '" + txtYear.Value + "-10-31 23:59:59'";
                        break;
                    case "11":
                        str = txtYear.Value + "-11-1 0:0:0' and '" + txtYear.Value + "-11-30 23:59:59'";
                        str2 = txtYear.Value + "-10-1 0:0:0' and '" + txtYear.Value + "-10-31 23:59:59'";
                        str3 = "'" + txtYear.Value + "-11-1 0:0:0' and '" + txtYear.Value + "-11-30 23:59:59'";
                        break;
                    case "12":
                        str = txtYear.Value + "-12-1 0:0:0' and '" + txtYear.Value + "-12-31 23:59:59'";
                        str2 = txtYear.Value + "-11-1 0:0:0' and '" + txtYear.Value + "-11-30 23:59:59'";
                        str3 = "'" + txtYear.Value + "-12-1 0:0:0' and '" + txtYear.Value + "-12-31 23:59:59'";
                        break;
                }
            }
            #endregion
            DataTable tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9, tmp10, tmp11, tmp12;
            tmp1 = new DataTable();
            tmp2 = new DataTable();
            tmp3 = new DataTable();
            tmp4 = new DataTable();
            tmp5 = new DataTable();
            tmp6 = new DataTable();
            tmp7 = new DataTable();
            tmp8 = new DataTable();
            tmp9 = new DataTable();
            tmp10 = new DataTable();
            tmp11 = new DataTable();
            tmp12 = new DataTable();
            int tmpInt1 = 0, tmpInt2 = 0, tmpInt3 = 0, tmpInt4 = 0, tmpInt5 = 0, tmpInt6 = 0, tmpInt7 = 0, tmpInt8 = 0, tmpInt9 = 0, tmpInt10 = 0, tmpInt11 = 0, tmpInt12 = 0;

            if (str != "")
            {
                #region 得到第一个表的数据
                tmp1 = mr.getNewCustomers(" and A.task_time between '" + str);
                tmp2 = mr.getNewCustomersIsFinished(" and A.task_time between '" + str + " and A.finish_time between '" + str);
                tmp3 = mr.getNewCustomersNumbers(" and A.request_time between '" + str);

                tmp4 = mr.getAdjustCustomers(" and A.task_time between '" + str);
                tmp5 = mr.getAdjustCustomersIsFinished(" and A.task_time between '" + str + " and A.finish_time between '" + str);
                tmp6 = mr.getAdjustCustomersNumbers(" and A.request_time between '" + str);

                tmp7 = mr.getCancelCustomers(" and A.task_time between '" + str);
                tmp8 = mr.getCancelCustomersIsFinished(" and A.task_time between '" + str + " and A.finish_time between '" + str);
                tmp9 = mr.getCancelCustomersNumbers(" and A.request_time between '" + str);
                #endregion

                #region 得到第二个表的数据
                tmp10 = mr.getNewReturnBill(str3);
                tmp11 = mr.getAdjustReturnBill(str3);
                tmp12 = mr.getCancelReturnBill(str3);
                #endregion

                #region 第一个表tab1
                for (int i = 2; i <= 7; i++)
                {
                    #region 先将所有单元格填0
                    tab1.Rows[i].Cells[1].InnerText = "0";
                    tab1.Rows[i].Cells[2].InnerText = "0";
                    tab1.Rows[i].Cells[3].InnerText = "0";
                    tab1.Rows[i].Cells[4].InnerText = "0";
                    tab1.Rows[i].Cells[5].InnerText = "0";
                    tab1.Rows[i].Cells[6].InnerText = "0";
                    tab1.Rows[i].Cells[7].InnerText = "0";
                    tab1.Rows[i].Cells[8].InnerText = "0";
                    tab1.Rows[i].Cells[9].InnerText = "0";
                    #endregion

                    #region 填充数据
                    for (int j = 0; j < tmp1.Rows.Count; j++)
                    {
                        if (tab1.Rows[i].Cells[0].InnerText.Trim().Replace("\r\n", "").Trim() == tmp1.Rows[j][0].ToString())
                        {
                            tab1.Rows[i].Cells[1].InnerText = tmp1.Rows[j][1].ToString();
                            tmpInt1 = tmpInt1 + Convert.ToInt32(tmp1.Rows[j][1]);
                        }
                    }
                    for (int j = 0; j < tmp2.Rows.Count; j++)
                    {
                        if (tab1.Rows[i].Cells[0].InnerText.Trim().Replace("\r\n", "").Trim() == tmp2.Rows[j][0].ToString())
                        {
                            tab1.Rows[i].Cells[2].InnerText = tmp2.Rows[j][1].ToString();
                            tmpInt2 = tmpInt2 + Convert.ToInt32(tmp2.Rows[j][1]);
                        }
                    }
                    for (int j = 0; j < tmp3.Rows.Count; j++)
                    {
                        if (tab1.Rows[i].Cells[0].InnerText.Trim().Replace("\r\n", "").Trim() == tmp3.Rows[j][0].ToString())
                        {
                            tab1.Rows[i].Cells[3].InnerText = (Convert.ToInt32(tmp3.Rows[j][1]) + Convert.ToInt32(tab1.Rows[i].Cells[1].InnerText)).ToString();
                            tmpInt3 = tmpInt3 + Convert.ToInt32(tab1.Rows[i].Cells[3].InnerText);
                        }
                    }
                    for (int j = 0; j < tmp4.Rows.Count; j++)
                    {
                        if (tab1.Rows[i].Cells[0].InnerText.Trim().Replace("\r\n", "").Trim() == tmp4.Rows[j][0].ToString())
                        {
                            tab1.Rows[i].Cells[4].InnerText = tmp4.Rows[j][1].ToString();
                            tmpInt4 = tmpInt4 + Convert.ToInt32(tmp4.Rows[j][1]);
                        }
                    }
                    for (int j = 0; j < tmp5.Rows.Count; j++)
                    {
                        if (tab1.Rows[i].Cells[0].InnerText.Trim().Replace("\r\n", "").Trim() == tmp5.Rows[j][0].ToString())
                        {
                            tab1.Rows[i].Cells[5].InnerText = tmp5.Rows[j][1].ToString();
                            tmpInt5 = tmpInt5 + Convert.ToInt32(tmp5.Rows[j][1]);
                        }
                    }
                    for (int j = 0; j < tmp6.Rows.Count; j++)
                    {
                        if (tab1.Rows[i].Cells[0].InnerText.Trim().Replace("\r\n", "").Trim() == tmp6.Rows[j][0].ToString())
                        {
                            tab1.Rows[i].Cells[6].InnerText = (Convert.ToInt32(tmp6.Rows[j][1]) + Convert.ToInt32(tab1.Rows[i].Cells[4].InnerText)).ToString();
                            tmpInt6 = tmpInt6 + Convert.ToInt32(tab1.Rows[i].Cells[6].InnerText);
                        }
                    }
                    for (int j = 0; j < tmp7.Rows.Count; j++)
                    {
                        if (tab1.Rows[i].Cells[0].InnerText.Trim().Replace("\r\n", "").Trim() == tmp7.Rows[j][0].ToString())
                        {
                            tab1.Rows[i].Cells[7].InnerText = tmp7.Rows[j][1].ToString();
                            tmpInt7 = tmpInt7 + Convert.ToInt32(tmp7.Rows[j][1]);
                        }
                    }
                    for (int j = 0; j < tmp8.Rows.Count; j++)
                    {
                        if (tab1.Rows[i].Cells[0].InnerText.Trim().Replace("\r\n", "").Trim() == tmp8.Rows[j][0].ToString())
                        {
                            tab1.Rows[i].Cells[8].InnerText = tmp8.Rows[j][1].ToString();
                            tmpInt8 = tmpInt8 + Convert.ToInt32(tmp8.Rows[j][1]);
                        }
                    }
                    for (int j = 0; j < tmp9.Rows.Count; j++)
                    {
                        if (tab1.Rows[i].Cells[0].InnerText.Trim().Replace("\r\n", "").Trim() == tmp9.Rows[j][0].ToString())
                        {
                            tab1.Rows[i].Cells[9].InnerText = (Convert.ToInt32(tmp9.Rows[j][1]) + Convert.ToInt32(tab1.Rows[i].Cells[7].InnerText)).ToString();
                            tmpInt9 = tmpInt9 + Convert.ToInt32(tab1.Rows[i].Cells[9].InnerText);
                        }
                    }
                    #endregion
                }

                #region 填充总计
                tab1.Rows[8].Cells[1].InnerText = tmpInt1.ToString();
                tab1.Rows[8].Cells[2].InnerText = tmpInt2.ToString();
                tab1.Rows[8].Cells[3].InnerText = tmpInt3.ToString();
                tab1.Rows[8].Cells[4].InnerText = tmpInt4.ToString();
                tab1.Rows[8].Cells[5].InnerText = tmpInt5.ToString();
                tab1.Rows[8].Cells[6].InnerText = tmpInt6.ToString();
                tab1.Rows[8].Cells[7].InnerText = tmpInt7.ToString();
                tab1.Rows[8].Cells[8].InnerText = tmpInt8.ToString();
                tab1.Rows[8].Cells[9].InnerText = tmpInt9.ToString();
                #endregion

                #region 填充上月
                int[] tmp = new int[9] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
                tmp = mr.getPrevMonth("'" + str2);
                tab1.Rows[9].Cells[1].InnerText = (tmpInt1 - tmp[0]).ToString();
                tab1.Rows[9].Cells[2].InnerText = (tmpInt2 - tmp[1]).ToString();
                tab1.Rows[9].Cells[3].InnerText = (tmpInt3 - tmp[2]).ToString();
                tab1.Rows[9].Cells[4].InnerText = (tmpInt4 - tmp[3]).ToString();
                tab1.Rows[9].Cells[5].InnerText = (tmpInt5 - tmp[4]).ToString();
                tab1.Rows[9].Cells[6].InnerText = (tmpInt6 - tmp[5]).ToString();
                tab1.Rows[9].Cells[7].InnerText = (tmpInt7 - tmp[6]).ToString();
                tab1.Rows[9].Cells[8].InnerText = (tmpInt8 - tmp[7]).ToString();
                tab1.Rows[9].Cells[9].InnerText = (tmpInt9 - tmp[8]).ToString();
                #endregion

                #region 填充文本描述
                Label1.Text = "0";
                Label2.Text = "0";
                Label3.Text = "0";
                Label4.Text = "0";
                Label5.Text = "0";
                Label6.Text = "0";
                Label7.Text = "0";
                Label8.Text = "0";
                Label9.Text = "0";
                Label10.Text = "0";
                Label11.Text = "0";
                Label12.Text = "0";
                Label13.Text = "0";
                Label14.Text = "0";
                Label15.Text = "0";
                Label1.Text = txtYear.Value + "&nbsp;年&nbsp;" + seleMonth.Value;
                Label2.Text = tmpInt1.ToString();
                Label6.Text = tab1.Rows[2].Cells[1].InnerText;
                Label8.Text = tab1.Rows[3].Cells[1].InnerText;
                Label10.Text = tab1.Rows[4].Cells[1].InnerText;
                if (tmpInt1 != 0)
                {
                    Label7.Text = Math.Round(Math.Round((decimal)Convert.ToInt32(Label6.Text) / (decimal)tmpInt1, 4) * 100, 2).ToString();
                    Label9.Text = Math.Round(Math.Round((decimal)Convert.ToInt32(Label8.Text) / (decimal)tmpInt1, 4) * 100, 2).ToString();
                    Label11.Text = Math.Round(Math.Round((decimal)Convert.ToInt32(Label10.Text) / (decimal)tmpInt1, 4) * 100, 2).ToString();
                }
                Label12.Text = (tmpInt3 + tmpInt6 + tmpInt9).ToString();
                Label3.Text = tmp[0].ToString();
                Label4.Text = tab1.Rows[9].Cells[1].InnerText;
                if (tmp[0] != 0)
                    Label5.Text = Math.Round(Math.Round((decimal)Convert.ToInt32(Label4.Text) / (decimal)tmp[0], 4) * 100, 2).ToString();
                Label13.Text = (tmp[2] + tmp[5] + tmp[8]).ToString();
                Label14.Text = ((tmpInt3 + tmpInt6 + tmpInt9) - (tmp[2] + tmp[5] + tmp[8])).ToString();
                if ((tmp[2] + tmp[5] + tmp[8]) != 0)
                    Label15.Text = Math.Round(Math.Round((decimal)Convert.ToInt32(Label14.Text) / (decimal)Convert.ToInt32(Label13.Text), 4) * 100, 2).ToString();
                #endregion

                #endregion

                #region 第二个表tab2
                for (int i = 2; i <= 7; i++)
                {
                    tab2.Rows[i].Cells[1].InnerText = tab1.Rows[i].Cells[1].InnerText;
                    tab2.Rows[i].Cells[2].InnerText = "0";
                    tab2.Rows[i].Cells[3].InnerText = "0";
                    tab2.Rows[i].Cells[4].InnerText = "0 %";
                    tab2.Rows[i].Cells[5].InnerText = tab1.Rows[i].Cells[4].InnerText;
                    tab2.Rows[i].Cells[6].InnerText = "0";
                    tab2.Rows[i].Cells[7].InnerText = "0";
                    tab2.Rows[i].Cells[8].InnerText = "0 %";
                    tab2.Rows[i].Cells[9].InnerText = tab1.Rows[i].Cells[7].InnerText;
                    tab2.Rows[i].Cells[10].InnerText = "0";
                    tab2.Rows[i].Cells[11].InnerText = "0";
                    tab2.Rows[i].Cells[12].InnerText = "0 %";
                    for (int j = 0; j < tmp10.Rows.Count; j++)
                    {
                        if (tab2.Rows[i].Cells[0].InnerText.Trim().Replace("\r\n", "").Trim() == tmp10.Rows[j][0].ToString())
                        {
                            tab2.Rows[i].Cells[3].InnerText = tab2.Rows[i].Cells[2].InnerText = tmp10.Rows[j][1].ToString();
                            tmpInt10 = tmpInt10 + Convert.ToInt32(tmp10.Rows[j][1]);
                        }
                    }
                    for (int j = 0; j < tmp11.Rows.Count; j++)
                    {
                        if (tab2.Rows[i].Cells[0].InnerText.Trim().Replace("\r\n", "").Trim() == tmp11.Rows[j][0].ToString())
                        {
                            tab2.Rows[i].Cells[7].InnerText = tab2.Rows[i].Cells[6].InnerText = tmp11.Rows[j][1].ToString();
                            tmpInt11 = tmpInt11 + Convert.ToInt32(tmp11.Rows[j][1]);
                        }
                    }
                    for (int j = 0; j < tmp12.Rows.Count; j++)
                    {
                        if (tab2.Rows[i].Cells[0].InnerText.Trim().Replace("\r\n", "").Trim() == tmp12.Rows[j][0].ToString())
                        {
                            tab2.Rows[i].Cells[11].InnerText = tab2.Rows[i].Cells[10].InnerText = tmp12.Rows[j][1].ToString();
                            tmpInt12 = tmpInt12 + Convert.ToInt32(tmp12.Rows[j][1]);
                        }
                    }

                    if (Convert.ToInt32(tab2.Rows[i].Cells[1].InnerText) != 0)
                        tab2.Rows[i].Cells[4].InnerText = Math.Round(Math.Round(Convert.ToDecimal(tab2.Rows[i].Cells[3].InnerText) / Convert.ToDecimal(tab2.Rows[i].Cells[1].InnerText), 4) * 100, 2).ToString() + " %";
                    if (Convert.ToInt32(tab2.Rows[i].Cells[5].InnerText) != 0)
                        tab2.Rows[i].Cells[8].InnerText = Math.Round(Math.Round(Convert.ToDecimal(tab2.Rows[i].Cells[7].InnerText) / Convert.ToDecimal(tab2.Rows[i].Cells[5].InnerText), 4) * 100, 2).ToString() + " %";
                    if (Convert.ToInt32(tab2.Rows[i].Cells[9].InnerText) != 0)
                        tab2.Rows[i].Cells[12].InnerText = Math.Round(Math.Round(Convert.ToDecimal(tab2.Rows[i].Cells[11].InnerText) / Convert.ToDecimal(tab2.Rows[i].Cells[9].InnerText), 4) * 100, 2).ToString() + " %";
                }

                tab2.Rows[8].Cells[1].InnerText = tab1.Rows[8].Cells[1].InnerText;
                tab2.Rows[8].Cells[2].InnerText = tmpInt10.ToString();
                tab2.Rows[8].Cells[3].InnerText = tmpInt10.ToString();
                if (tmpInt1 != 0)
                    tab2.Rows[8].Cells[4].InnerText = Math.Round(Math.Round((decimal)tmpInt10 / (decimal)tmpInt1, 4) * 100, 2).ToString() + " %";
                else
                    tab2.Rows[8].Cells[4].InnerText = "0 %";
                tab2.Rows[8].Cells[5].InnerText = tab1.Rows[8].Cells[4].InnerText;
                tab2.Rows[8].Cells[6].InnerText = tmpInt11.ToString();
                tab2.Rows[8].Cells[7].InnerText = tmpInt11.ToString();
                if (tmpInt4 != 0)
                    tab2.Rows[8].Cells[8].InnerText = Math.Round(Math.Round((decimal)tmpInt11 / (decimal)tmpInt4, 4) * 100, 2).ToString() + " %";
                else
                    tab2.Rows[8].Cells[8].InnerText = "0 %";
                tab2.Rows[8].Cells[9].InnerText = tab1.Rows[8].Cells[7].InnerText;
                tab2.Rows[8].Cells[10].InnerText = tmpInt12.ToString();
                tab2.Rows[8].Cells[11].InnerText = tmpInt12.ToString();
                if (tmpInt7 != 0)
                    tab2.Rows[8].Cells[12].InnerText = Math.Round(Math.Round((decimal)tmpInt12 / (decimal)tmpInt7, 4) * 100, 2).ToString() + " %";
                else
                    tab2.Rows[8].Cells[12].InnerText = "0 %";
                #endregion

                #region 第三个表tab3
                for (int i = 2; i <= 7; i++)
                {
                    tab3.Rows[i - 1].Cells[1].InnerText = tab1.Rows[i].Cells[1].InnerText;
                    tab3.Rows[i - 1].Cells[2].InnerText = tab1.Rows[i].Cells[2].InnerText;
                    tab3.Rows[i - 1].Cells[3].InnerText = (Convert.ToInt32(tab1.Rows[i].Cells[1].InnerText) - Convert.ToInt32(tab1.Rows[i].Cells[2].InnerText)).ToString();
                }
                tab3.Rows[7].Cells[1].InnerText = tab1.Rows[8].Cells[1].InnerText;
                tab3.Rows[7].Cells[2].InnerText = tab1.Rows[8].Cells[2].InnerText;
                tab3.Rows[7].Cells[3].InnerText = (Convert.ToInt32(tab3.Rows[7].Cells[1].InnerText) - Convert.ToInt32(tab3.Rows[7].Cells[2].InnerText)).ToString();
                #endregion
            }
        }
    }
}
